{% extends 'home.html' %}
{% block right_content %}
    <ol class="breadcrumb">
        <li><a href="{{ url_for('backend_page.home') }}">数据可视化系统</a></li>
        <li><a href="{{ url_for('kingadmin_page.table_list') }}">数据表管理</a></li>
        <li><a href="{{ url_for('kingadmin_page.table_model', model_name=model_name) }}">{{ model_name }}表</a></li>
        <li class="active">编辑</li>
    </ol>
    <div class="row" style="margin-top: 30px;">
        <form class="form-horizontal" id="fm">
            <input type="text" style="display: none;" name="id" value="{{ id }}">
            {% for field in fields %}
                <div class="form-group">
                    <label for="content" class="col-sm-2 control-label">{{ field }}</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" name="{{ field }}" placeholder="无" value="{{ get_obj_attr(data, field) }}">
                    </div>
                </div>
            {% endfor %}
        </form>
        <button class="btn btn-primary" style="float: right" onclick="sendEdit();">保存</button>
    </div>
{% endblock %}

{% block js %}
    <script>
     function sendEdit() {
            $.ajax({
                type: 'POST',
                data: $('#fm').serialize(),
                dataType: 'JSON',
                success: function (arg) {
                    var callback = null;
                    console.log(arg)
                    if (arg.code == 1000) {
                        callback = function() {
                            window.location.href = '{{ buildUrl( url_for('kingadmin_page.table_model', model_name=model_name) )}}';
                        }
                    }
                    common_ops.alert(arg.msg, callback)
                }
            })
        }
</script>
{% endblock %}